package com.zq.sysuser.controller;

import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.sysuser.dao.entity.Useractions;
import com.zq.sysuser.service.IUseractionsService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author 张乔
 * @Date 2025/2/28 21:11
 */
@RestController
@RequestMapping("/sys/useractions")
public class UseractionsController {


    @Resource
    private IUseractionsService useractionsService;

//    根据条件分页查询日志
@GetMapping("/getPageLogs/{page}/{limit}")
public Result<PageInfo<Useractions>> getPageLogs(@PathVariable("page") Integer page,
                                                 @PathVariable("limit") Integer limit,
                                                 @RequestParam("userName") String userName) {
PageInfo<Useractions> pageInfo=    useractionsService.getPageLogs(page, limit, userName);

    return Result.successData(pageInfo);

}

@PostMapping("/save")
    public Result<Useractions> add(@RequestBody Useractions useractions) {
    useractions.setActionTime(LocalDateTime.now());
        useractionsService.save(useractions);
    return Result.success();
}

@PutMapping("/update")
    public Result<Useractions> update(@RequestBody Useractions useractions) {
        useractionsService.updateById(useractions);
    return Result.success();
}
@DeleteMapping("/deleteById/{id}")
public Result<Useractions> delete(@PathVariable("id") Integer id) {
    useractionsService.removeById(id);
    return Result.success();

}


}
